package cn.itcast.weatherapp123.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

import cn.itcast.weatherapp123.R;
import cn.itcast.weatherapp123.bend.HoursBean;

public class HoureAdapter extends RecyclerView.Adapter<HoureAdapter.HoureViewHold> {

    private List<HoursBean> hoursBeanList;
    private Context mContext;

    public HoureAdapter(Context Context ,List<HoursBean> mhoursBeanList){

        this.hoursBeanList=mhoursBeanList;
        this.mContext=Context;

    }

    @NonNull
    @Override
    public HoureViewHold onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

        View view= LayoutInflater.from(mContext).inflate(R.layout.houre_item_activity,parent,false);
        HoureViewHold houreViewHold=new HoureViewHold(view);
        return houreViewHold;

    }

    @Override
    public void onBindViewHolder(@NonNull HoureViewHold holder, int position) {
        HoursBean hoursBean=hoursBeanList.get(position);
        holder.tv_time.setText(hoursBean.getHours());
        holder.tv_tem.setText(hoursBean.getTem()+"°C");
        holder.tv_win.setText(hoursBean.getWin()+hoursBean.getWin_speed());
        holder.tv_qing.setText(hoursBean.getWea());
        holder.iv_weather.setImageResource(getImResOfWeather(hoursBean.getWea_img()));
    }



    @Override
    public int getItemCount() {

        return (hoursBeanList==null)?0:hoursBeanList.size();

    }

    class HoureViewHold extends RecyclerView.ViewHolder{
          TextView tv_time,tv_tem,tv_qing,tv_win;
          ImageView iv_weather;
        public HoureViewHold(@NonNull View itemView) {
            super(itemView);

            tv_tem=itemView.findViewById(R.id.tv_tem);
            tv_time=itemView.findViewById(R.id.tv_time);
            tv_qing=itemView.findViewById(R.id.tv_qing);
            tv_win=itemView.findViewById(R.id.tv_qing);
            iv_weather=itemView.findViewById(R.id.iv_weather);

        }
    }
    private int getImResOfWeather(String wea_img) {
        int result = 0;

        switch (wea_img){

            case "qing":
                result = R.mipmap.qing;
                break;
            case "yin":
                result = R.mipmap.yin;
                break;
            case "yu":
                result = R.mipmap.yu;
                break;
            case "bingbao":
                result = R.mipmap.bingbao;
                break;
            case "wu":
                result = R.mipmap.wu;
                break;
            case "shachen":
                result = R.mipmap.shachen;
                break;
            case "lei":
                result = R.mipmap.lei;
                break;
            case "xue":
                result = R.mipmap.xue;
                break;
            case "yun":
                result=R.mipmap.yun;
                break;
        }
        return result;
    }
}

